<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.6.8" />
<link rel="Shortcut Icon" href="/images/favicon.ico" type="image/x-icon" />
<title></title>
<link rel="stylesheet" href="asciidoc-2.css" tppabs="http://old.peachfuzzer.com/v2/asciidoc.css" type="text/css" />
<link rel="stylesheet" href="website-2.css" tppabs="http://old.peachfuzzer.com/v2/website.css" type="text/css" />
</head>

<body>

<div id="layout-menu-box">
<div id="layout-menu">
  <div><a href="WhatIsPeach.html" tppabs="http://old.peachfuzzer.com/WhatIsPeach.html">What is Peach</a></div>
  <div><a href="Installation.html" tppabs="http://old.peachfuzzer.com/v3/Installation.html"><b>Installing</b></a></div>
  <div><a href="PeachQuickStart.html" tppabs="http://old.peachfuzzer.com/v3/PeachQuickStart.html"><b>Tutorials</b></a></div>
  <div><a href="Methodology.html" tppabs="http://old.peachfuzzer.com/Methodology.html">Methodology</a></div>
  <div><a href="Introduction.html" tppabs="http://old.peachfuzzer.com/Introduction.html">Introduction</a></div>
  <div><a href="Training.html" tppabs="http://old.peachfuzzer.com/Training.html">Training</a></div>
  <div><a href="javascript:if(confirm(%27http://www.dejavusecurity.com/peach.html  \n\nThis file was not retrieved by Teleport Ultra, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?%27))window.location=%27http://www.dejavusecurity.com/peach.html%27" tppabs="http://www.dejavusecurity.com/peach.html">Enterprise</a></div>
  <div><a href="FAQ.html" tppabs="http://old.peachfuzzer.com/v3/FAQ.html">FAQ</a></div>
  <div><a href="javascript:if(confirm(%27http://forums.peachfuzzer.com/forum.php  \n\nThis file was not retrieved by Teleport Ultra, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?%27))window.location=%27http://forums.peachfuzzer.com/forum.php%27" tppabs="http://forums.peachfuzzer.com/forum.php">Support Forums</a></div>

  <div><h5>Peach 3</h5></div>
  <div><img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><a href="PeachPit.html" tppabs="http://old.peachfuzzer.com/v3/PeachPit.html">Peach Pits</a></div>
  <div>&nbsp;<img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><a href="GeneralConfiguration.html" tppabs="http://old.peachfuzzer.com/v3/GeneralConfiguration.html">General Conf</a></div>
  <div>&nbsp;<img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><a href="DataModeling.html" tppabs="http://old.peachfuzzer.com/v3/DataModeling.html">Data Modeling</a></div>
  <div>&nbsp;<img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><a href="StateModel.html" tppabs="http://old.peachfuzzer.com/v3/StateModel.html">State Modeling</a></div>
  <div>&nbsp;<img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><a href="AgentsMonitors.html" tppabs="http://old.peachfuzzer.com/v3/AgentsMonitors.html">Agents</a></div>
  <div>&nbsp;&nbsp;<img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><a href="AgentsMonitors.html" tppabs="http://old.peachfuzzer.com/v3/AgentsMonitors.html">Monitors</a></div>
  <div>&nbsp;<img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><a href="TestConfig.html" tppabs="http://old.peachfuzzer.com/v3/TestConfig.html">Test</a></div>
        <div>&nbsp;&nbsp;<img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><a href="Publisher.html" tppabs="http://old.peachfuzzer.com/v3/Publisher.html">Publishers</a></div>
  <div>&nbsp;&nbsp;<img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><a href="Logger.html" tppabs="http://old.peachfuzzer.com/v3/Logger.html">Loggers</a></div>
  <!-- <div>&nbsp;<img src="/images/1.gif" /><a href="/v3/DebuggingPitFiles.html">Debugging Pits</a></div> -->
  <!-- <div>&nbsp;<img src="/images/1.gif" /><a href="/v3/ValidatingPitFiles.html">Validating Pits</a></div> -->
  <div><img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><a href="RunningPeach.html" tppabs="http://old.peachfuzzer.com/v3/RunningPeach.html">Running</a></div>
  <!-- <div><img src="/images/1.gif" /><a href="/v3/ParallelPeach.html">Parallel</a></div> -->
  <!-- <div><img src="/images/1.gif" /><a href="/v3/ExtendingPeach.html">Extending</a></div> -->
  <div><img src="1.gif" tppabs="http://old.peachfuzzer.com/images/1.gif" /><a href="minset.html" tppabs="http://old.peachfuzzer.com/v3/minset.html">Minset</a></div>

  <div><h5><a href="peach23.html" tppabs="http://old.peachfuzzer.com/v2/peach23.html">Peach 2.3</a></h5></div>

  <div><hr/></div>

  <div><a href="License.html" tppabs="http://old.peachfuzzer.com/License.html">License</a></div>
</div>
</div>
<div id="layout-content-box">
<div id="layout-banner">
  <div id="layout-title">
    <a href="index.htm" tppabs="http://old.peachfuzzer.com/"><img src="peach_fuzzer.png" tppabs="http://old.peachfuzzer.com/images/peach_fuzzer.png" height="100" /></a>
    <a href="javascript:if(confirm(%27http://www.dejavusecurity.com/peach.html  \n\nThis file was not retrieved by Teleport Ultra, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?%27))window.location=%27http://www.dejavusecurity.com/peach.html%27" tppabs="http://www.dejavusecurity.com/peach.html" class="layout-inner-banner-right">
                <img height="50" src="dejavusecurity.png" tppabs="http://old.peachfuzzer.com/images/dejavusecurity.png" /></a>
  </div>

  <div id="layout-description">
  <script>
  (function() {
    var cx = '007028538774543840348:g-0dlrdlmxs';
    var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>
      </div>
</div>
<div id="layout-content">
<div id="content">
<div class="sect1">
<h2 id="_create_a_custom_mutator">Create a Custom Mutator</h2>
<div class="sectionbody">
<div class="paragraph"><p>Creating a custom mutator is fairly easy.  Mutators should be written to perform one type of change to a data element.  There is no limit to the number of mutators that can be used by Peach.</p></div>
<div class="paragraph"><p>The code you write should live in a <em>.py</em> file in the same folder as your <em>.xml</em> file.  This will make it all much easier to package up.  See the PythonPath and <a href="Import-1.html" tppabs="http://old.peachfuzzer.com/v2/Import.html">Import</a> elements for how to include your new code into your Peach XML file.</p></div>
<div class="paragraph"><p>Once you have created your mutator and added the required <a href="Import-1.html" tppabs="http://old.peachfuzzer.com/v2/Import.html">Import</a> statement you will need to tell Peach to use it.  You can do this two ways.</p></div>
<div class="ulist"><ul>
<li>
<p>
Add it to the default list of mutators.  This will cause every Pit to get this mutator.  You can do this by editing defaults.xml.  You will want to add your <a href="Import-1.html" tppabs="http://old.peachfuzzer.com/v2/Import.html">Import</a> statement and also a Mutator element.
</p>
</li>
<li>
<p>
Create a list of mutators in a specific Pit file in the <a href="Test-1.html" tppabs="http://old.peachfuzzer.com/v2/Test.html">Test</a> element like this (note, only listed mutators are used):
</p>
</li>
</ul></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.7
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">&lt;Test&gt;</span></span>
  <span style="font-weight: bold"><span style="color: #0000FF">&lt;Mutator</span></span> <span style="color: #009900">class</span><span style="color: #990000">=</span><span style="color: #FF0000">"StaticSet"</span> <span style="font-weight: bold"><span style="color: #0000FF">/&gt;</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">&lt;/Test&gt;</span></span></tt></pre></div></div>
<div class="paragraph"><p><strong>NOTE:</strong> Never add the code into the Peach source folders!  You&#8217;re welcome to submit them as patches, but otherwise keep them in another folder.  This will make it easier to move to another machine, and upgrade Peach in the future.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.7
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>
<span style="font-weight: bold"><span style="color: #000080">from</span></span> Peach<span style="color: #990000">.</span>mutator <span style="font-weight: bold"><span style="color: #000080">import</span></span> <span style="color: #990000">*</span>
<span style="font-weight: bold"><span style="color: #000080">from</span></span> Peach<span style="color: #990000">.</span>Engine<span style="color: #990000">.</span>common <span style="font-weight: bold"><span style="color: #000080">import</span></span> <span style="color: #990000">*</span>

<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> <span style="font-weight: bold"><span style="color: #000000">StaticSet</span></span><span style="color: #990000">(</span>Mutator<span style="color: #990000">):</span>
<span style="font-style: italic"><span style="color: #9A1900">        '''</span></span>
<span style="font-style: italic"><span style="color: #9A1900">        This mutator will iterate through an array of values</span></span>
<span style="font-style: italic"><span style="color: #9A1900">        returning them one at a time.</span></span>
<span style="font-style: italic"><span style="color: #9A1900">        '''</span></span>

        <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> <span style="font-weight: bold"><span style="color: #000000">__init__</span></span><span style="color: #990000">(</span>self<span style="color: #990000">,</span> peach<span style="color: #990000">,</span> node<span style="color: #990000">):</span>
                Mutator<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">__init__</span></span><span style="color: #990000">(</span>self<span style="color: #990000">)</span>

                <span style="font-style: italic"><span style="color: #9A1900"># Do we have a finite number of values</span></span>
                <span style="font-style: italic"><span style="color: #9A1900"># to produce?</span></span>
                self<span style="color: #990000">.</span>isFinite <span style="color: #990000">=</span> True

                <span style="font-style: italic"><span style="color: #9A1900"># Name of mutator (typically same as class)</span></span>
                self<span style="color: #990000">.</span>name <span style="color: #990000">=</span> <span style="color: #FF0000">"StaticSet"</span>

                self<span style="color: #990000">.</span>_peach <span style="color: #990000">=</span> peach

                <span style="font-style: italic"><span style="color: #9A1900"># Here is our list of values</span></span>
                self<span style="color: #990000">.</span>_values <span style="color: #990000">=</span> <span style="color: #990000">[</span>
                        <span style="color: #FF0000">'Value #1'</span><span style="color: #990000">,</span>
                        <span style="color: #FF0000">'Value #2'</span><span style="color: #990000">,</span>
<span style="font-style: italic"><span style="color: #9A1900">                        'Value #3'</span></span>
                        <span style="color: #990000">]</span>

                self<span style="color: #990000">.</span>_count <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">len</span></span><span style="color: #990000">(</span>self<span style="color: #990000">.</span>_values<span style="color: #990000">)</span>

                <span style="font-style: italic"><span style="color: #9A1900"># Our position in _values</span></span>
                self<span style="color: #990000">.</span>_index <span style="color: #990000">=</span> <span style="color: #993399">0</span>

        <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> <span style="font-weight: bold"><span style="color: #000000">next</span></span><span style="color: #990000">(</span>self<span style="color: #990000">):</span>
<span style="font-style: italic"><span style="color: #9A1900">                '''</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                Move to the next value we can produce.  If</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                we run out of values throw the "MutatorCompleted()"</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                exception.</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                '''</span></span>

                self<span style="color: #990000">.</span>_index <span style="color: #990000">+=</span> <span style="color: #993399">1</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> self<span style="color: #990000">.</span>_index <span style="color: #990000">&gt;=</span> self<span style="color: #990000">.</span>_count<span style="color: #990000">:</span>
                        <span style="font-weight: bold"><span style="color: #0000FF">raise</span></span> <span style="font-weight: bold"><span style="color: #000000">MutatorCompleted</span></span><span style="color: #990000">()</span>

        <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> <span style="font-weight: bold"><span style="color: #000000">getCount</span></span><span style="color: #990000">(</span>self<span style="color: #990000">):</span>
<span style="font-style: italic"><span style="color: #9A1900">                '''</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                Return the total number of values we can produce</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                '''</span></span>
                <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> self<span style="color: #990000">.</span>_count

        <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> <span style="font-weight: bold"><span style="color: #000000">supportedDataElement</span></span><span style="color: #990000">(</span>node<span style="color: #990000">):</span>
<span style="font-style: italic"><span style="color: #9A1900">                '''</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                Can we produce values for a DataElement.</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                '''</span></span>

                <span style="font-style: italic"><span style="color: #9A1900"># For our example mutator we will only support</span></span>
                <span style="font-style: italic"><span style="color: #9A1900"># 'String' types that are mutable.</span></span>

                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #000000">isinstance</span></span><span style="color: #990000">(</span>node<span style="color: #990000">,</span> String<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">and</span></span> node<span style="color: #990000">.</span>isMutable<span style="color: #990000">:</span>
                        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> True

                <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> False
        supportedDataElement <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">staticmethod</span></span><span style="color: #990000">(</span>supportedDataElement<span style="color: #990000">)</span>

        <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> <span style="font-weight: bold"><span style="color: #000000">sequencialMutation</span></span><span style="color: #990000">(</span>self<span style="color: #990000">,</span> node<span style="color: #990000">):</span>
<span style="font-style: italic"><span style="color: #9A1900">                '''</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                A value from this mutator in sequence.  Until next()</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                is called this method will return the same value.</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                '''</span></span>

                self<span style="color: #990000">.</span>changedName <span style="color: #990000">=</span> node<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">getFullnameInDataModel</span></span><span style="color: #990000">()</span>
                node<span style="color: #990000">.</span>currentValue <span style="color: #990000">=</span> self<span style="color: #990000">.</span>_values<span style="color: #990000">[</span>self<span style="color: #990000">.</span>_index<span style="color: #990000">]</span>

        <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> <span style="font-weight: bold"><span style="color: #000000">randomMutation</span></span><span style="color: #990000">(</span>self<span style="color: #990000">,</span> node<span style="color: #990000">,</span> rand<span style="color: #990000">):</span>
<span style="font-style: italic"><span style="color: #9A1900">                '''</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                Use the provided rand variable to produce a random value</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                from our _values set.  Each call to this method will</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                produce a different value.</span></span>
<span style="font-style: italic"><span style="color: #9A1900">                '''</span></span>

                self<span style="color: #990000">.</span>changedName <span style="color: #990000">=</span> node<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">getFullnameInDataModel</span></span><span style="color: #990000">()</span>
                node<span style="color: #990000">.</span>currentValue <span style="color: #990000">=</span> rand<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">choice</span></span><span style="color: #990000">(</span>self<span style="color: #990000">.</span>_values<span style="color: #990000">)</span>

<span style="font-style: italic"><span style="color: #9A1900"># end</span></span>
</tt></pre></div></div>
</div>
</div>
</div>
<div id="footnotes"></div>
<div id="footer">
<div id="footer-text">

<table width="100%">
<td><td>
<a href="javascript:if(confirm(%27http://dejavusecurity.com/  \n\nThis file was not retrieved by Teleport Ultra, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?%27))window.location=%27http://dejavusecurity.com/%27" tppabs="http://dejavusecurity.com/"><img src="dejavusecurity.png" tppabs="http://old.peachfuzzer.com/images/dejavusecurity.png" height="50"/></a>
</td><td>&nbsp;&nbsp;&nbsp;</td><td>

Copyright (c) <a href="javascript:if(confirm(%27http://dejavusecurity.com/  \n\nThis file was not retrieved by Teleport Ultra, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?%27))window.location=%27http://dejavusecurity.com/%27" tppabs="http://dejavusecurity.com/">Deja vu Security</a> <br/>
Last updated 2014-02-23 21:20:58 PST
</td>
</table>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-1094513-10']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www/') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</div>
</div>
</div>
</div>
</body>
</html>
